<template>
	<view class="agreement_bos" ref="content" id="content">
		<view>
			<template v-if="type == 'healthInfoAuth'">
				<view class="title">《{{ protocol.healthInfoAuth.title || '' }}》</view>
				<rich-text :nodes="protocol.healthInfoAuth.content"></rich-text>
			</template>
			<template v-if="type == 'legalStatement'">
				<view class="title">《{{ protocol.legalStatement.title || '' }}》</view>
				<rich-text :nodes="protocol.legalStatement.content"></rich-text>
			</template>
			<template v-if="type == 'privacyPolicy'">
				<view class="title">《{{ protocol.privacyPolicy.title || '' }}》</view>
				<rich-text :nodes="protocol.privacyPolicy.content"></rich-text>
			</template>
			<template v-if="type == 'riskNotice'">
				<view class="title">《{{ protocol.riskNotice.title || '' }}》</view>
				<rich-text :nodes="protocol.riskNotice.content"></rich-text>
			</template>
			<template v-if="type == 'user'">
				<view class="title">《{{ protocol.user.title || '' }}》</view>
				<rich-text :nodes="protocol.user.content"></rich-text>
			</template>
		</view>
		<view v-if="type == 2">
			<view class="title">《{{ protocol.fast.title || '' }}》</view>
			<rich-text :nodes="protocol.fast.content"></rich-text>
		</view>
		<u-bottom-button v-if="disabled" disabled="true" value="已阅读并同意" @click="save()"></u-bottom-button>
		<u-bottom-button v-else value="已阅读并同意" @click="save()"></u-bottom-button>
	</view>
</template>

<script>
	import uBottomButton from '@/components/u-bottom-button/u-bottom-button.vue';
	export default {
		components: {
			uBottomButton
		},
		data() {
			return {
				protocol: {},
				disabled: true,
				height1: 0,
				height2: 0,
				type: '',

			}
		},
		onLoad(options) {
			let _this = this
			let httpType = ''
			this.type = options.type
			if (options.type == 2) {
				httpType = 'fast'
			} else {
				httpType = options.type
			}
			// if (options.type == 1) {
			// 	httpType = 'user,riskNotice,healthInfoAuth,legalStatement,privacyPolicy'
			// } else if (options.type == 2) {
			// 	httpType = 'fast'
			// }
			uni.getSystemInfo({
				success: (res => {
					_this.height2 = res.windowHeight
				})
			});

			this.$api.getProtocolsByType({
				type: httpType
			}).then(e => {
				const {
					code,
					result
				} = e
				if (code == 200) {
					this.protocol = result
					this.checkOverflow();
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
				}
			})
		},
		methods: {
			checkOverflow() {
				let _this = this
				let query = uni.createSelectorQuery();
				query.select('#content').boundingClientRect(data => {
					_this.height1 = data.height
					if (_this.height1 >= _this.height2) {
						_this.disabled = true
					} else {
						_this.disabled = false
					}
				}).exec();
			},
			save() {
				uni.$emit('choosePath', true)
				// 关闭当前页面
				uni.navigateBack({
					delta: 1
				});
			}
		},
		onReachBottom() {
			this.disabled = false
		},
	}
</script>

<style lang="less" scoped>
	view,
	scroll-view,
	cover-view,
	text,
	input,
	textarea,
	button {
		box-sizing: border-box;
	}

	.agreement_bos {
		padding: 25rpx 25rpx 160rpx 25rpx;

		.title {
			font-size: 32rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #000000;
			width: 100%;
			text-align: center;
			padding-bottom: 20rpx;
			margin-top: 20rpx;
		}

		.adasd {
			height: 2000rpx;
			background-color: red;
			width: 100%;
		}
	}
</style>